<?php
if (!defined('BASEPATH')) {
	exit('No direct script access allowed');
}

class M_feedback1_layanan extends CI_Model {

	public function __construct() {
		parent::__construct();
	}

	function get($tgl_awal,$tgl_akhir,$ppk) {
		$sql = 'SELECT kd_klaim, nama, tgl_masuk, tgl_keluar, DateDiff(tgl_keluar,tgl_masuk) AS los,
		jenis_kunjungan, status
		FROM klaim
		LEFT JOIN surat_jaminan ON klaim.kd_surat_jaminan = surat_jaminan.kd_surat_jaminan
		LEFT JOIN master_jenis_kunjungan ON surat_jaminan.id_jenis_kunjungan = master_jenis_kunjungan.id_jenis_kunjungan
		LEFT JOIN peserta ON surat_jaminan.kd_peserta = peserta.kd_peserta
		LEFT JOIN penduduk ON peserta.nik = penduduk.nik
		WHERE tgl_klaim BETWEEN "'.$tgl_awal.'" AND "'.$tgl_akhir.'" AND kd_ppk = "'.$ppk.'"';
		return $sql;
	}

	function get_by($kd_klaim) {
		$sql = 'SELECT kd_klaim, nama, tgl_masuk, tgl_keluar, DateDiff(tgl_keluar,tgl_masuk) AS los,
		jenis_kunjungan, status, tempat_lahir, tgl_lahir, jk, diagnosa_lain, peserta.kd_peserta
		FROM klaim
		LEFT JOIN surat_jaminan ON klaim.kd_surat_jaminan = surat_jaminan.kd_surat_jaminan
		LEFT JOIN master_jenis_kunjungan ON surat_jaminan.id_jenis_kunjungan = master_jenis_kunjungan.id_jenis_kunjungan
		LEFT JOIN peserta ON surat_jaminan.kd_peserta = peserta.kd_peserta
		LEFT JOIN penduduk ON peserta.nik = penduduk.nik 
		LEFT JOIN keluarga ON penduduk.kd_kk = keluarga.kd_kk
		WHERE kd_klaim = ?';
		$query = $this->db->query($sql, $kd_klaim);
		if ($query->num_rows() > 0) {
			$result = $query->row_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result;
	}

	function get_detail_ppk($kd_ppk) {
		$sql = 'SELECT * FROM ppk WHERE kd_ppk = ?';
		$query = $this->db->query($sql, $kd_ppk);
		if ($query->num_rows() > 0) {
			$result = $query->row_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result;
	}

	function get_diagnosa($params) {
		$sql = 'SELECT * FROM klaim_diagnosa 
		INNER JOIN master_diagnosa ON klaim_diagnosa.kd_diagnosa = master_diagnosa.kd_diagnosa
		WHERE kd_klaim = ?';
		$query = $this->db->query($sql, $params);
		if ($query->num_rows() > 0) {
			$result = $query->result_array();
			$query->free_result();
		} else {
			$result = array();
		}
		return $result;
	}
}
